package com.bop.dehong.dialog;

import com.base.dehong.R;

import android.R.id;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.Gravity;

/**
 * @author Tangwenhan
 *2015年12月3日下午5:48:28
 */
public class NetworkErrorDialog {
	private  Dialog mDialog ;
	
	private static NetworkErrorDialog instance;
	public static NetworkErrorDialog getInstance(){
		if (instance == null) {
			instance = new NetworkErrorDialog();
		}
		return instance;
	}
	

	public void show(Context context){
		if (mDialog == null) {
			initDialog(context);
		}
		if (!mDialog.isShowing()) {
			mDialog.show();
			new Handler().postDelayed(new Runnable() {
				
				@Override
				public void run() {
					if (mDialog != null) {
						mDialog.dismiss();
					}
				}
			}, 1500);
		}
	}
	public  void dismiss(){
		if (mDialog != null) {
			mDialog.dismiss();
			mDialog = null;
		}
	}
	private void initDialog(Context context){
		mDialog = new Dialog(context, R.style.MyDialogStyle2);
		mDialog.getWindow().setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画  
		mDialog.getWindow().setGravity(Gravity.TOP);
		mDialog.setContentView(R.layout.dialog_net_erroe);
		mDialog.setCancelable(false);
	}
}

